#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

//https://leetcode.cn/problems/binary-tree-preorder-traversal/

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

// 二叉树节点的个数
int TreeSize(struct TreeNode* root) {
    return root == NULL ? 0 : TreeSize(root->left) + TreeSize(root->right) + 1;
}

// 前序遍历二叉树
void BinaryTraversal(struct TreeNode *root, int *rets, int *count) {
    if (root == NULL) {
        return;
    }
    rets[(*count)++] = root->val;
    BinaryTraversal(root->left, rets, count);
    BinaryTraversal(root->right, rets, count);
};

//  二叉树主函数
int *preorderTraversal(struct TreeNode *root, int *returnSize) {
    int *rets = (int *)malloc(TreeSize(root) * sizeof(struct TreeNode));
    int *count = returnSize;
    *count = 0;
    BinaryTraversal(root, rets, count);
    return rets;
}

int main() {

    return 0;
}


